<?

class render_rss
{
	public static function action( action_controller $action )
	{
		response::set_header('Content-Type', 'text/xml; charset=utf-8');

		$xml = new XMLWriter();
		$xml->openURI('php://output');
		$xml->startDocument('1.0');

		$xml->startElement('rss');
		$xml->writeAttribute('version', '2.0');

		$xml->startElement("channel");
		$xml->writeElement('title', $action->rss['title']);
		$xml->writeElement('description', $action->rss['description']);
		$xml->writeElement('link', $action->rss['link'] ? $action->rss['link'] : 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
		$xml->writeElement('lastBuildDate', date("D, d M Y H:i:s e"));
		$xml->writeElement('language', i18n::get_language());

		foreach ( $action->rss['items'] as $item )
		{
			$xml->startElement("item");
			$xml->writeElement('title', $item['title']);
			$xml->writeElement('link', $item['link']);
			$xml->writeElement('description', $item['description']);
			$xml->writeElement('guid', $item['link']);

			$xml->writeElement('pubDate', date("D, d M Y H:i:s e", $item['ts']));
			$xml->endElement();
		}

		$xml->endElement();
		$xml->endElement();

		return $xml->outputMemory();
	}
}